
Ext.define('SHApp.CompanyManage.AgentProduct.Tree', {
    extend: 'SH.Core.BaseTree',
    alias: 'widget.agentProductTree',
    fields: ["id", "text", "leaf", "City", "CityCode"],
    displayField: "City",
    dataUrl: "api/agentProductTree?format=json",
    rootVisible: false,
    rootText: "委托城市",
    btnAddID: "_btnAddID",
    btnDeleteID: "_btnDeleteID",
    txtAreaNameID: "_txtAreaNameID",
    agentId: "",
    agentName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnDeleteID += me.id;
        me.txtAreaNameID += me.id;
        this.creatTbar();
        this.callParent(arguments);
    },
    listeners: {
        selectionchange: function (sm, selections) {
            if (this.down('#' + this.btnAddID) != null) {
                this.down('#' + this.btnAddID).setDisabled(selections.length == 0);
            }
            if (this.down('#' + this.btnDeleteID) != null) {
                this.down('#' + this.btnDeleteID).setDisabled(selections.length == 0);
            }
        }
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
            {
                xtype: 'areaComboBox',
                // fieldLabel: "城市",
                // labelWidth: 40,                
                id: me.txtAreaNameID
            }, ' ', {
                xtype: 'button',
                text: '添加',
                iconCls: 'icon-btn-add',
                id: me.btnAddID,
                handler: function () {
                    var vCityCode = me.down("#" + me.txtAreaNameID).getValue();
                    if (vCityCode == null || vCityCode.length == 0) {
                        Ext.Msg.alert("提示", "城市不能为空！");
                        return;
                    }
                    var vCityName = me.down("#" + me.txtAreaNameID).getDisplayValue();
                    if (true) {

                    }
                    if ((vCityCode != null && vCityCode.length > 0) && (vCityName != null && vCityName.length > 0)) {

                    }
                }
            }
        ];
    }
});

